#include "widget.h"
#include "ui_widget.h"
#include <QLabel>
#include <QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QLabel* label1 = new QLabel(ui->tab);
    label1->setText("我是第一个标签页");
    label1->resize(150,100);

    QLabel* label2 = new QLabel(ui->tab_2);
    label2->setText("我是第二个标签页");
    label2->resize(150,100);

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_add_clicked()
{
    int count = ui->tabWidget->count();
    //新增一个标签页
    QWidget* widget = new QWidget(ui->tabWidget);
    ui->tabWidget->addTab(widget,"Tab " + QString::number(count+1));
    QLabel* label = new QLabel(widget);
    label->setText("我是第" + QString::number(count+1) +"个标签页");
    label->resize(150,100);
    //设置选中新增的标签页
    ui->tabWidget->setCurrentIndex(count);
}



void Widget::on_pushButton_remove_clicked()
{
    //删除标签页
    int i = ui->tabWidget->currentIndex();
    ui->tabWidget->removeTab(i);

}

void Widget::on_tabWidget_currentChanged(int index)
{
    qDebug() <<"当前标签页：" <<  index;
}
